package com.jet.merchant.remote.office;

import com.jet.core.exception.CustomException;
import com.jet.core.result.ResultCode;
import com.jet.core.result.ResultJson;
import com.jet.merchant.remote.office.vo.IndustryAttrVo;
import com.jet.merchant.remote.office.vo.MerchantIndustryVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author dcl
 * @since 2025/2/21 17:30
 */
@Component
public class OfficeRemoteFallback implements FallbackFactory<OfficeRemoteFeign> {
    @Override
    public OfficeRemoteFeign create(Throwable cause) {
        return new OfficeRemoteFeign() {

            @Override
            public ResultJson<MerchantIndustryVo> getMerchantIndustry(long merchantNo) {
                if (cause instanceof CustomException) {
                    ResultJson<?> result = ((CustomException) cause).getResultJson();
                    return ResultJson.failure(result.getCode(), result.getMsg());
                }
                return ResultJson.failure(ResultCode.SERVICE_ERROR);
            }

            @Override
            public ResultJson<List<IndustryAttrVo>> getMerchantAbility(long merchantNo) {
                if (cause instanceof CustomException) {
                    ResultJson<?> result = ((CustomException) cause).getResultJson();
                    return ResultJson.failure(result.getCode(), result.getMsg());
                }
                return ResultJson.failure(ResultCode.SERVICE_ERROR);
            }

            @Override
            public ResultJson<Void> industryTrial(long merchantNo, long storeNo, String accountId) {
                if (cause instanceof CustomException) {
                    ResultJson<?> result = ((CustomException) cause).getResultJson();
                    return ResultJson.failure(result.getCode(), result.getMsg());
                }
                return ResultJson.failure(ResultCode.SERVICE_ERROR);
            }
        };
    }
}
